﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;
using System.Data;

public partial class SiteSachHay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Pager1.CurrentIndex = 1;
            HienThiSachHay(Pager1.CurrentIndex);
            Session["Title"] = "Album Sách Hay";
        }
    }

    private void HienThiSachHay(int PageNo)
    {
        int TotalRows = 0;
        string WhereClause = "1=1 and TrangThai=1";
        TList<SachHay> dsSachHay = DataRepository.SachHayProvider.GetPaged(WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
        dlSachHay.DataSource = dsSachHay;
        dlSachHay.DataBind();

        Pager1.ItemCount = TotalRows;
        H_PageCount.Value = Pager1.PageCount.ToString();
    }
    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        HienThiSachHay(currnetPageIndex);
    }

    /// <summary>
    /// Handles ItemDataBound, Binds ExchangesTo to the Child DataList
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlFromTrades_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            DataListItem parentList = e.Item;
            HiddenField lit_Name = (HiddenField)parentList.FindControl("H_SachHayId");
            string i = (lit_Name.Value).ToString();
            int j = Convert.ToInt32(i);            
        }
    }

    protected void cmdNext_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex + 1;
            HienThiSachHay(Pager1.CurrentIndex);
        }
    }

    protected void cmdPrevious_Click(object sender, ImageClickEventArgs e)
    {
        if (Pager1.CurrentIndex > 1)
        {
            Pager1.CurrentIndex = Pager1.CurrentIndex - 1;
            HienThiSachHay(Pager1.CurrentIndex);
        }
    }

    public string GetNoiDung(object noidung)
    {
        string sub = Server.HtmlDecode((Convert.ToString(noidung)));
        return sub;
    }

    public string GetLienKet()
    {
        return Common.sPathUpLienKet;
    }

    //public string GetLienKet(object LienKet)
    //{
    //    //if (Session["KhachHangVip"] != null)
    //    //{
    //        return Server.HtmlDecode(LienKet.ToString());
    //    //}
    //    //return "DangNhap.aspx";
    //}
    public string GetLienKets(object LienKet)
    {
        //if (Session["KhachHangVip"] != null)
        //{
        return Server.HtmlDecode(LienKet.ToString());
        //    }
        //    else
        //        return "Bạn phải đăng nhập";
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    public string GetNgay(object ngayviet)
    {
        DateTime s = Convert.ToDateTime(ngayviet);
        string v = s.ToString("dd/MM/yyyy");
        return Common.StandardStringjquery(v);
    }
}